

import cmdmaincontroler from "./command/cmdmaincontroler";
import menuControler from '../../script/manage/menuaction/menucontroler.js'

class CommandManager {
    constructor() {
        this.m_cmdList = [];
        this.mainCmdControler = new cmdmaincontroler.CMDMainControler();
        this.menuControler = new menuControler.MenuControler();
    }
    act2CMD(cmd, mainctl) {
        let list = cmd.split(" ");
        if (list.length < 1) {
            return null;
        }
        let nextTipObj = null;
        let rst = this.mainCmdControler.act2InputCMD(cmd, mainctl);
        if (rst) {
            if (rst.cmdObj) {
                this.m_cmdList.push(rst.cmdObj);
            }
            nextTipObj = { nextTips: rst.nextTips, appendToPreCMD: rst.appendToPreCMD };
        }
        else {
            nextTipObj = this.menuControler.setPreMenuRelateValue(cmd);
        }
        if (!nextTipObj){
            nextTipObj = { nextTips:"", appendToPreCMD: ""};
        }
        return nextTipObj;
    }

    notifyMapActionProcess(evt, mainctl) {
        let nextTipObj = null;
        let rst = this.mainCmdControler.actToNotifyMapActionProcess(evt, mainctl);
        if (rst) {
            if (rst.cmdObj) {
                this.m_cmdList.push(rst.cmdObj);
            }
            nextTipObj = { nextTips: rst.nextTips, appendToPreCMD: rst.appendToPreCMD,appendToPreNextCMD:rst.appendToPreNextCMD };
        }
        return nextTipObj;
    }

    sendCMD(cmd, mainctl) {
        let nextTipObj = null;
        let rst = this.menuControler.act2ClieckMenu(mainctl, cmd);
        if (rst) {
            if (rst.cmdObj) {
                this.m_cmdList.push(rst.cmdObj);
            }
            nextTipObj = { nextTips: rst.nextTips, appendToPreCMD: rst.appendToPreCMD };
            this.mainCmdControler.act2ToolBtnCMD(cmd,mainctl);
        }
        return nextTipObj;
    }

    actToSetDrawTool = function (drawTool, mainctl) {
        let nextTipObj = null;
        let rst = this.mainCmdControler.actToSetDrawTool(drawTool,mainctl);
        if (rst) {
            if (rst.cmdObj) {
                this.m_cmdList.push(rst.cmdObj);
            }
            nextTipObj = { nextTips: rst.nextTips, appendToPreCMD: rst.appendToPreCMD };
        }
        return nextTipObj;
    }
}

export default { CommandManager }